package sz.szsmk.citizencard.mvp.presenter;

import com.google.gson.Gson;

import java.util.List;

import javax.inject.Inject;

import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.ServiceNetReq;
import sz.szsmk.citizencard.model.network.bean.response.PrepayResponse;
import sz.szsmk.citizencard.mvp.contract.IMapViewContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.util.Constant;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/3/5 15:34
 * description:
 */
public class IMapViewPresenter extends IBasePresenter
        implements IMapViewContact.IMapViewPresenter<IMapViewContact.IMapViewView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public IMapViewPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }


    @Override
    public void getServiceNet(String mLongitude, String mLatitude, String service_type, String site_type) {
        ServiceNetReq serviceNetReq = new ServiceNetReq();
        serviceNetReq.setLatitude(mLatitude);
        serviceNetReq.setLongitude(mLongitude);
        serviceNetReq.setDistance_type("5000");
        serviceNetReq.setPage_num(1 + "");
        serviceNetReq.setPage_size("15");
        serviceNetReq.setService_type(service_type);
        serviceNetReq.setSite_type(site_type);
        String json = new Gson().toJson(serviceNetReq);
        L.e(Constant.TAG, "getWebsiteList----" + json);
        mNetworkDateSource.websiteList(serviceNetReq, new SubscribeResult<PrepayResponse>() {
            @Override
            protected void onOk(PrepayResponse response) {

                String toJson = new Gson().toJson(response);
                L.e(Constant.TAG, "getWebsiteList----res" + toJson);
                List<PrepayResponse.WebsiteListInfoBean> websiteListInfo = response.getWebsiteListInfo();
                ((IMapViewContact.IMapViewView) mView).getServiceNetSucc(websiteListInfo);
            }

            @Override
            protected void onFailure(PrepayResponse response) {
                super.onFailure(response);
                ((IMapViewContact.IMapViewView) mView).getServiceNetFail(response);

            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
//                ((IMapViewContact.IMapViewView) mView).getServiceNetSucc(response);

            }
        });
    }
}
